package vip.meeet.jdk.stream;


import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

public class WordStream {

    public static long getWorldCount() throws IOException {
//        InputStream resourceAsStream = WordStream.class.getResourceAsStream("stream.txt");
        URL url = WordStream.class.getResource("stream.txt");
        String file = url.getFile().substring(1);
        Path path = Paths.get(file);
        String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
        String[] contents = content.split("[\\P{L}]+");
        List<String> words = Arrays.asList(contents);
//        return words.stream().filter(w -> w.length() > 12).count();
        return words.parallelStream().filter(w -> w.length() > 12).count();
    }
}
